package com.bdqn.t350;

import com.bdqn.t350.pojo.SysUser;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
//        Scanner input = new Scanner(System.in);
//        System.out.println("请输入你要创建的类:");
//        String next = input.nextLine();
//        //动态的去创建类的实例
//        Class clz = Class.forName(next);
//        Object instance = clz.newInstance();
//        Method[] declaredMethods = clz.getDeclaredMethods();
//        System.out.println("该类的所有方法:");
//        for (Method declaredMethod : declaredMethods) {
//            System.out.println(declaredMethod);
//        }
//        System.out.println("请选择您要调用的方法:");
//        String next_method = input.nextLine();
//        String method = next_method.substring(next_method.lastIndexOf(".") + 1, next_method.lastIndexOf("("));
//        Method show = clz.getDeclaredMethod(method, null);
//        show.invoke(instance);

        //单例模式
        //1、在程序只允许有一个实例
        //2、不允许外界去new  将构造方法设置为私有，自己去创建实例
        //3、提供外界去获取实例的方法

        Class clz = Class.forName("com.bdqn.t350.pojo.SysUser");
        //Object instance1 = clz.newInstance();
        //Object instance2 = clz.newInstance();

        Constructor declaredConstructor = clz.getDeclaredConstructor(Integer.class);
        declaredConstructor.setAccessible(true);//强行访问私有方法
        declaredConstructor.newInstance(500);

        //com.bdqn.t350.pojo.SysUser user1 = new com.bdqn.t350.pojo.SysUser();

    }
}
